import 'package:get/get.dart';
import 'package:gt_flutter_admin/pages/dashboard/dashboard_controller.dart';
import 'package:gt_flutter_admin/pages/login/login_controller.dart';
import 'package:gt_flutter_admin/pages/system/menu/menu_update_contrller.dart';
import 'package:gt_flutter_admin/pages/system/role/role_controller.dart';
import 'package:gt_flutter_admin/pages/system/role/role_update_controller.dart';
import 'package:gt_flutter_admin/pages/system/user/user_controller.dart';
import 'package:gt_flutter_admin/pages/system/user/user_update_controller.dart';
import 'package:gt_flutter_admin/pages/system/dept/dept_view.dart';
import 'package:gt_flutter_admin/pages/system/menu/menu_update_view.dart';
import 'package:gt_flutter_admin/pages/system/role/role_update_view.dart';
import 'package:gt_flutter_admin/pages/system/role/role_view.dart';
import 'package:gt_flutter_admin/layout/root_view.dart';
import 'package:gt_flutter_admin/pages/system/user/user_update_view.dart';
import 'package:gt_flutter_admin/widgets/image_picker/image_picker_controller.dart';

import '../pages/system/dept/dept_controller.dart';
import '../pages/system/dept/dept_update_controller.dart';
import '../layout/root_controller.dart';
import '../middlewares/auth_middleware.dart';
import '../pages/dashboard/dashboard_view.dart';
import '../pages/system/dept/dept_update_view.dart';
import '../pages/login/login_view.dart';
import '../pages/system/user/user_view.dart';

/// 路由跳转路径
abstract class Routes {
  static const LOGIN = Paths.LOGIN;

  static const ROOT = Paths.ROOT;

  static const USER = Paths.USER;
  static const USER_UPDATE = Paths.USER + Paths.UPDATE;

  static const MENU_UPDATE = Paths.MENU + Paths.UPDATE;

  static const ROLE = Paths.ROLE;
  static const ROLE_UPDATE = Paths.ROLE + Paths.UPDATE;

  static const DEPT = Paths.DEPT;
  static const DEPT_UPDATE = Paths.DEPT + Paths.UPDATE;

  static const DASHBOARD = Paths.DASHBOARD;
}

/// 路由路径
abstract class Paths {
  static const UPDATE = '/update';

  static const LOGIN = '/login';

  static const ROOT = '/';

  static const USER = '/user';

  static const MENU = '/menu';

  static const ROLE = '/role';

  static const DEPT = '/dept';

  static const DASHBOARD = '/dashboard';
}

final routes = [
  GetPage(
    participatesInRootNavigator: true,
    preventDuplicates: true,
    middlewares: [EnsureAuthMiddleware()],
    name: Paths.ROOT,
    page: () => RootView(),
    binding: BindingsBuilder.put(() => RootController()),
    children: [
      GetPage(
        name: Paths.DASHBOARD,
        page: () => DashboardView(),
        binding: BindingsBuilder.put(() => DashboardController()),
        title: '首页',
      ),
      GetPage(
        name: Paths.USER,
        page: () => UserView(),
        binding: BindingsBuilder.put(() => UserController()),
        title: '用户管理',
        children: [
          GetPage(
            name: Paths.UPDATE,
            page: () => UserUpdateView(),
            binding: BindingsBuilder(() {
              Get.lazyPut(() => UserUpdateController());
              Get.lazyPut(() => ImagePickerController());
            }),
            title: '用户管理',
          ),
        ],
      ),
      GetPage(
        name: Routes.MENU_UPDATE,
        page: () => MenuUpdateView(),
        binding: BindingsBuilder.put(() => MenuUpdateController()),
        title: '菜单管理',
      ),
      GetPage(
        name: Paths.ROLE,
        page: () => RoleView(),
        binding: BindingsBuilder.put(() => RoleController()),
        title: '角色管理',
        children: [
          GetPage(
            name: Paths.UPDATE,
            page: () => RoleUpdateView(),
            binding: BindingsBuilder.put(() => RoleUpdateController()),
            title: '角色管理',
          ),
        ],
      ),
      GetPage(
        name: Paths.DEPT,
        page: () => DeptView(),
        binding: BindingsBuilder.put(() => DeptController()),
        title: '部门管理',
        children: [
          GetPage(
            name: Paths.UPDATE,
            page: () => DeptUpdateView(),
            binding: BindingsBuilder.put(() => DeptUpdateController()),
            title: '部门管理',
          ),
        ],
      ),
    ],
  ),
  GetPage(
    participatesInRootNavigator: true,
    middlewares: [EnsureNotAuthedMiddleware()],
    name: Paths.LOGIN,
    page: () => LoginView(),
    binding: BindingsBuilder.put(() => LoginController()),
  ),
];
